<template>
	<view>
		<uni-grid :column="3" :square="false">
			<!-- square:宫格项是否为方形 -->
			<uni-grid-item v-for="{bid,bname,keywords,logo,popularity} in brands" :key="bid">
				<view class="brand" @click="goToList(bname,keywords)">
					<uni-badge :text="popularity" type="error" absolute="rightTop" :max-num="9999" :offset="[5,0]">
						<image :src="base+logo" mode="widthFix"></image>
					</uni-badge>
					<text>{{bname}}</text>
				</view>
			</uni-grid-item>
		</uni-grid>
	</view>
</template>

<script>
	import {
		base,
		productBrand
	} from '../../service'
	export default {
		data() {
			return {
				base: base,
				brands: [], //服务器端返回的品牌列表
			}
		},
		//生命周期方法 -- 页面记载完成
		async onLoad() {
			//向服务器端异步请求所有的品牌数据
			let data = await productBrand()
			this.brands = data
		},
		methods: {
			goToList(bname,kw){
				//跳转到商品列表页,子二代查询参数:品牌名称\该品牌搜索关键字
				uni.navigateTo({
					url:`/pages/list/list?bname=${bname}&$kw=${kw}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.brand {
		//弹性容器内的子元素在交叉轴居中对齐
		align-items: center;
		padding: $uni-spacing-col-lg 0;

		image {
			width: 190rpx;
		}

		text {
			margin-top: $uni-spacing-col-base;
		}
	}
</style>
